package ebnf.ebnfGrammar;

import java.util.ArrayList;

import ebnf.ebnfScannerParser.EBNFToken;

/**
 * 
 * @author Sander Meijer & Bart Wentink
 *
 */
public class NonTerminal extends EBNFToken {
	
	private ArrayList<Expression> expressions;
	
	/**
	 * Creates a NonTerminal from the given values
	 * @param {@link Integer} kind
	 * @param {@link Integer} line
	 * @param {@link Integer} column
	 * @param {@link String} text
	 */
	public NonTerminal(int kind,int line,int column,String text) {
		super(kind,line,column,text);
		expressions = new ArrayList<Expression>();
	}
	
	/**
	 * Creates a NonTerminal with the given token.
	 * @param {@link EBNFToken} token
	 */
	public NonTerminal(EBNFToken token){
		super(token.getKind(), token.getLine(), token.getColumn(), token.getText());
		expressions = new ArrayList<Expression>();
	}
	
	/**
	 * Adds an expression
	 * @param [@link Expression} expression
	 */
	public void addExpression(Expression expression) {
		expressions.add(expression);
	}
	
	/**
	 * Prints the NonTerminal
	 */
	public void print(){
		String s = "";
		s += getText() + " = ";
		for(int rule = 0; rule < expressions.size(); rule++ ){
			s += expressions.get(rule).toString();
			if(rule + 1 < expressions.size()){
				s += "| ";
			}
		}
		s += ";";
		System.out.println(s);
	}
	
	/**
	 * Get all the expressions.
	 * @return {@link ArrayList}<{@link Expression}> expressions
	 */
	public ArrayList<Expression> getExpressions(){
		return expressions;
	}
	
	/**
	 * @return {@link String} string
	 */
	public String toString() {
		String s = "";
		s += getText() + " = ";
		for(int rule = 0; rule < expressions.size(); rule++ ){
			s += expressions.get(rule).toString();
			if(rule + 1 < expressions.size()){
				s += "| ";
			}
		}
		s += ";";
		return s;
	}
}
